package io.renren.modules.task.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.sys.controller.AbstractController;
import io.renren.modules.task.entity.MtCcEquipmentRunInfoLogEntity;
import io.renren.modules.task.service.MtCcEquipmentRunInfoLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2019-04-23 09:03:44
 */
@RestController
@Api(description = "操作报表接口")
@RequestMapping("generator/mtccequipmentruninfolog")
public class MtCcEquipmentRunInfoLogController extends AbstractController {
    @Autowired
    private MtCcEquipmentRunInfoLogService mtCcEquipmentRunInfoLogService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("generator:mtccequipmentruninfolog:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = mtCcEquipmentRunInfoLogService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("generator:mtccequipmentruninfolog:info")
    public R info(@PathVariable("id") Integer id){
		MtCcEquipmentRunInfoLogEntity mtCcEquipmentRunInfoLog = mtCcEquipmentRunInfoLogService.getById(id);

        return R.ok().put("mtCcEquipmentRunInfoLog", mtCcEquipmentRunInfoLog);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("generator:mtccequipmentruninfolog:save")
    public R save(@RequestBody MtCcEquipmentRunInfoLogEntity mtCcEquipmentRunInfoLog){
		mtCcEquipmentRunInfoLogService.save(mtCcEquipmentRunInfoLog);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("generator:mtccequipmentruninfolog:update")
    public R update(@RequestBody MtCcEquipmentRunInfoLogEntity mtCcEquipmentRunInfoLog){
		mtCcEquipmentRunInfoLogService.updateById(mtCcEquipmentRunInfoLog);
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("generator:mtccequipmentruninfolog:delete")
    public R delete(@RequestBody Integer[] ids){
		mtCcEquipmentRunInfoLogService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 工作台的报表统计
     */
    @RequestMapping("/select/console/log/test")
    @ApiOperation(value = "工作台报表统计测试" , notes = "工作台报表统计测试")
    public R selectConsloeLog(@RequestParam Map<String, Object> params){
        PageUtils page = mtCcEquipmentRunInfoLogService.queryPageByTerm(params);
        return R.ok().put("page", page);
    }

    /**
     * 工作台的报表统计EXCEL导出
     */
    @PostMapping(value = "/console/log/excel",produces = {"application/octet-stream;charset=UTF-8"})
//    @PostMapping(value = "/console/log/excel",produces = {"application/vnd.ms-excel;charset=UTF-8"})
    @ApiOperation(value = "工作台报表统计EXCEL导出测试" , notes = "工作台报表统计EXCEL导出测试")
    public String consoleLogToExcel(HttpServletResponse response,@RequestBody Map<String, Object> params){
        return mtCcEquipmentRunInfoLogService.consoleLogToExcel(response,params);
    }

    /**
     * 工作台的操作条件显示
     */
    @PostMapping("/select/run/info/log")
    @ApiOperation(value = "工作台的操作条件显示" , notes = "工作台的操作条件显示")
    public R selectRunInfoLogByConsole(@RequestBody Map<String, Object> params){
        params.put("console",getUser().getConsoleCode());
        List<MtCcEquipmentRunInfoLogEntity> list =
                mtCcEquipmentRunInfoLogService.selectRunInfoLogByConsole(params);
        return R.ok().put("list",list);
    }
}